package com.woniuxy.controller;

import com.woniuxy.dao.FeesManagerMapper;
import com.woniuxy.pojo.*;
import com.woniuxy.service.FeesManagerService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.util.ResultDto;
import com.woniuxy.vo.FeesManagerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class FeesManagerController extends BaseController{
    @Autowired
    private FeesManagerService feesManagerService;
    @Autowired
    private FeesManagerMapper feesManagerMapper;
    @GetMapping(value = "/feesManagers")
    public DataGridView selectFeesManagersByProperty(FeesManagerVo feesManagerVo) {
        return feesManagerService.selectFeesManagersByProperty(feesManagerVo);
    }

    @DeleteMapping(value = "/feesManagers/{id}")
    public ResultDto deleteRepairRecordById(@PathVariable("id") int id) {
        try {
            this.feesManagerService.deleteFeesManagerById(id);
            return ResultDto.DELETE_FEE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultDto.DELETE_FEE_FAILURE;
        }
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/feesManagers/deleteBathFeesManager")
    public ResultDto removeFeesManagers(@RequestParam("ids[]") Integer[] ids) {
        try {
            this.feesManagerService.removeFeesManager(ids);
            return ResultDto.DELETE_FEE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultDto.DELETE_FEE_FAILURE;
        }
    }
    @GetMapping("/feesManagers/cars.do")
    public List<Car> cars() {
        return feesManagerMapper.selectAllCars();
    }

    @GetMapping("/feesManagers/units.do")
    public List<CurrentUnit> selectAllUnit() {
        return feesManagerMapper.selectAllUnit();
    }

    @GetMapping("/feesManagers/users.do")
    public List<User> users() {
        return feesManagerMapper.selectAllUsers();
    }

    @PostMapping(value = "/feesManagers.do")
    public ResultDto addFeesManager(FeesManager feesManager) {
        boolean flag = this.feesManagerService.insertFeesManager(feesManager);
        if (flag) {
            return ResultDto.FEE_ADD_SUCCESS;
        } else {
            return ResultDto.FEE_ADD_FAIL;
        }
    }
    @PostMapping(value = "/feesManagers/update.do")
    public ResultDto updateFeesManager(FeesManager feesManager) {
        boolean flag = this.feesManagerService.updataFeesManager(feesManager);
        if (flag) {
            return ResultDto.FEE_UPDATE_SUCCESS;
        } else {
            return ResultDto.FEE_UPDATE_FAIL;
        }
    }
}
